﻿using System;
using System.Collections.Generic;

using ApplicationBoilerplate.DataProvider;
using ApplicationBoilerplate.DependencyInjection;

using Raven.Client;

namespace MVCBootstrap.RavenDB.DependencyInjection {

	public class DataProviderBuilder : IDependencyBuilder {
		private readonly String connectionName;

		public DataProviderBuilder()
			: this(String.Empty) {
		}

		public DataProviderBuilder(String connectionName) {
			this.connectionName = String.IsNullOrWhiteSpace(connectionName) ? "DataProvider.RavenDB" : connectionName;
		}

		public void Configure(IDependencyContainer container) {
			container.RegisterPerRequest<ISession, Session>(new Dictionary<String, Object> { { "connectionStringName", this.connectionName } });
			//container.RegisterGeneric(typeof(IRepository<>), typeof(Repository<>));
			container.RegisterPerRequest<IContext, Session>(new Dictionary<String, Object> { { "connectionStringName", this.connectionName } });
			container.RegisterGeneric(typeof(IRepository<>), typeof(Repository<>));
		}

		public void ValidateRequirements(IList<ApplicationRequirement> feedback) {
		}
	}
}
